package TCP3;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Mythread extends Thread {
    private Socket socket;
    public Mythread(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {

            System.out.println("Thread running");
            try {
                InputStream in = socket.getInputStream();
                DataInputStream dis = new DataInputStream(in);
                while (true) {
                   String mes= dis.readUTF();
                    System.out.println( mes);
                    System.out.print("对方的IP："+socket.getInetAddress().getHostAddress());
                    System.out.println("对方的端口："+socket.getPort());
                }
            } catch (IOException e) {
//                e.printStackTrace();
                System.out.println("客户端下线了，ip："+socket.getInetAddress().getHostAddress());
            }


        // Do something with the socket here
    }
}
